/*    */ package com.zimbra.cs.account.callback;
/*    */ 
/*    */ import com.zimbra.common.service.ServiceException;
/*    */ import com.zimbra.common.util.Log;
/*    */ import com.zimbra.common.util.ZimbraLog;
/*    */ import com.zimbra.cs.account.Account;
/*    */ import com.zimbra.cs.account.AttributeCallback;
/*    */ import com.zimbra.cs.account.AttributeCallback.SingleValueMod;
/*    */ import com.zimbra.cs.account.Entry;
/*    */ import java.util.Map;
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ 
/*    */ public class PrefMailForwardingAddress
/*    */   extends AttributeCallback
/*    */ {
/*    */   public void preModify(CallbackContext context, String attrName, Object attrValue, Map attrsToModify, Entry entry)
/*    */     throws ServiceException
/*    */   {
/* 47 */     if ((entry != null) && (!(entry instanceof Account))) {
/* 48 */       return;
/*    */     }
/*    */     
/* 51 */     AttributeCallback.SingleValueMod mod = singleValueMod(attrsToModify, attrName);
/* 52 */     if (mod.unsetting()) {
/* 53 */       return;
/*    */     }
/* 55 */     int maxLen = -1;
/* 56 */     int maxAddrs = -1;
/*    */     
/* 58 */     String maxLenInCtxt = context.getData(CallbackContext.DataKey.MAIL_FORWARDING_ADDRESS_MAX_LEN);
/* 59 */     if (maxLenInCtxt != null) {
/*    */       try {
/* 61 */         maxLen = Integer.parseInt(maxLenInCtxt);
/*    */       } catch (NumberFormatException e) {
/* 63 */         ZimbraLog.account.warn("encountered invalid " + CallbackContext.DataKey.MAIL_FORWARDING_ADDRESS_MAX_LEN.name() + ": " + maxLenInCtxt);
/*    */       }
/*    */     }
/*    */     
/*    */ 
/* 68 */     String maxAddrsInCtxt = context.getData(CallbackContext.DataKey.MAIL_FORWARDING_ADDRESS_MAX_NUM_ADDRS);
/* 69 */     if (maxAddrsInCtxt != null) {
/*    */       try {
/* 71 */         maxLen = Integer.parseInt(maxAddrsInCtxt);
/*    */       } catch (NumberFormatException e) {
/* 73 */         ZimbraLog.account.warn("encountered invalid " + CallbackContext.DataKey.MAIL_FORWARDING_ADDRESS_MAX_NUM_ADDRS.name() + ": " + maxAddrsInCtxt);
/*    */       }
/*    */     }
/*    */     
/*    */ 
/*    */ 
/* 79 */     if (entry == null) {
/* 80 */       return;
/*    */     }
/* 82 */     Account account = (Account)entry;
/* 83 */     if (maxLen == -1) {
/* 84 */       maxLen = account.getMailForwardingAddressMaxLength();
/*    */     }
/* 86 */     if (maxAddrs == -1) {
/* 87 */       maxAddrs = account.getMailForwardingAddressMaxNumAddrs();
/*    */     }
/* 89 */     String newValue = mod.value();
/*    */     
/* 91 */     if (newValue.length() > maxLen) {
/* 92 */       throw ServiceException.INVALID_REQUEST("value is too long, the limit(zimbraMailForwardingAddressMaxLength) is " + maxLen, null);
/*    */     }
/*    */     
/*    */ 
/*    */ 
/* 97 */     String[] addrs = newValue.split(",");
/* 98 */     if (addrs.length > maxAddrs) {
/* 99 */       throw ServiceException.INVALID_REQUEST("value is too long, the limit(zimbraMailForwardingAddressMaxNumAddrs) is " + maxAddrs, null);
/*    */     }
/*    */   }
/*    */   
/*    */   public void postModify(CallbackContext context, String attrName, Entry entry) {}
/*    */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/callback/PrefMailForwardingAddress.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */